
var head = {}
/**
 * 获取胶囊按钮位置
 */
head.getMenuPosition = (_this, systemInfo) => {
  let top = 4
  let right = 7
  let width = 87
  let height = 32
  
  if (systemInfo.platform === 'devtools' && systemInfo.system.indexOf('Android') === -1) {
    top = 6
    right = 10
  } else if (systemInfo.platform === 'devtools' && systemInfo.system.indexOf('Android') != -1) {
    top = 8
    right = 10
  } else if (systemInfo.system.indexOf('Android') != -1) {
    top = 8
    right = 10
    width = 95
  }
  
  // #ifdef H5
  top = 6
  width = 0
  // #endif
  
  _this.navigationBarTop = top
  _this.capsuleInfo = { top, right, width, height}
  _this.navigationH = height
  return {
    top: systemInfo.statusBarHeight + top,
    left: systemInfo.windowWidth - width - right,
    width: width,
    height: height
  }
}
/**
 * 获取状态栏样式
 */
head.getStatusBarStyle = (_this, systemInfo) => {
  let statusBarPosition = {
    top: 0,
    left: 0,
    width: systemInfo.windowWidth,
    height: systemInfo.statusBarHeight
  }
  return formatStyle(statusBarPosition)
}
/**
 * 获取导航栏样式
 */
head.getNavigationBarStyle = (_this, systemInfo) => {
  let menuPosition = head.getMenuPosition(_this, systemInfo)
  // #ifdef MP-WEIXIN
  let height = (menuPosition.top - systemInfo.statusBarHeight) * 2 + menuPosition.height
  // #endif
  
  // #ifdef H5
  let height = (4 - systemInfo.statusBarHeight) * 2 + menuPosition.height
  // #endif
  
  let navigationBarPosition = {
    top: systemInfo.statusBarHeight,
    left: 0,
    width: systemInfo.windowWidth,
    height: height,
  }
  // IOS真机在navigationBar下面多加4个像素，保持和原生一致
  if (systemInfo.platform !== 'devtools' && systemInfo.system.indexOf('Android') === -1) {
    navigationBarPosition.height = navigationBarPosition.height + 4
  }
  
    _this.navigationBarH= navigationBarPosition.height
    _this.statusBarH= systemInfo.statusBarHeight
    _this.totalH= navigationBarPosition.height + systemInfo.statusBarHeight
  return formatStyle(navigationBarPosition)
}
/**
 * 获取导航样式
 */
head.getNavigationStyle = (_this, systemInfo) => {
  let menuPosition = head.getMenuPosition(_this, systemInfo)
  let padding = systemInfo.windowWidth - menuPosition.left - menuPosition.width
  let width = systemInfo.windowWidth - padding * 2
  // #ifdef MP-WEIXIN
  width = systemInfo.windowWidth - padding * 3 - menuPosition.width
  // #endif
  let navigationPosition = {
    top: menuPosition.top,
    left: padding,
    width: width,
    height: menuPosition.height
  }
  return formatStyle(navigationPosition)
}
/**
 * 获取胶囊按钮样式
 */
head.getMenuStyle = (_this, systemInfo) => {
  return formatStyle(head.getMenuPosition(_this, systemInfo))
}
/**
 * 格式化Style
 */
const formatStyle = (position) => {
  let styles = []
  for (let key in position) {
    styles.push(`${key}: ${position[key]}px;`)
  }
  return styles.join(' ')
}

module.exports = head;